package com.example.demo.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.example.demo.entity.Admin;
import com.example.demo.entity.Laboratory;
import com.example.demo.entity.User;
import com.example.demo.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserService {



    @Autowired
    private RedisTemplate redisTemplate;

    @Autowired
    private UserMapper userMapper;

    public User getLongIn(String userName, String password){
        return userMapper.getLongIn(userName,password);
    }

    public List<User> list(User user){
        LambdaQueryWrapper<User> queryWrapper = Wrappers.lambdaQuery(user);
        return userMapper.selectList(queryWrapper);
    }
    /**
     * 根据ID查询用户
     * @param id
     * @return
     */
    public User getById(Long id){
        return userMapper.selectById(id);
    }


    public User register(User user){

        User userName = userMapper.findUserName(user.getUsername());
        if(userName!=null){
            userName.setRegister(false);
            return userName;
        }else {
            userMapper.insert(user);
            user.setRegister(true);
            return user;
        }

    }

    public int delete(Long id){
        return userMapper.deleteById(id);
    }

}